//
//  STDSGlowLightEffect.h
//  STDSRenderSDKIOS
//
//  Created by 陈学明 on 2023/4/3.
//

#ifndef STDSGlowLightEffect_h
#define STDSGlowLightEffect_h


#include "STDSBaseEffect.hpp"

class STDSGlowLightEffect: public STDSBaseEffect {
public:
    STDSGlowLightEffect() {
        mEffectType = STDSEffectTypeGlowLight;
    }
    ~STDSGlowLightEffect() {
//        printf("dealloc--STDSMosaicEffect\n");
    }
    
    void initGL() override {
        STDSBaseEffect::initGL();
    }
    
    void setFloatArguments(const char *name, float *floatValue, int n) override {
        mParam1 = *floatValue;
    }
    
public:
    shared_ptr<STDSShaderProgram> getEffectProgram() {
        if (mGlowLightProgram == nullptr) {
            mGlowLightProgram = mContext->getProgram(kShaderSRCGlowLight);
        }
        return mGlowLightProgram;
    }
    
    void draw() override {
        auto program = getEffectProgram();
        if (program == nullptr) {
            return;
        }
        if (mTexture == nullptr) {
            return;
        }
        
        program->use();
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, mTexture->getId());
        program->setUniform(program->getUniform("inputImageTexture"), 0);
        program->setUniform(program->getUniform("param1"), mParam1);
        
        mAtbRect.setPosVex(program->getAttrib("aPos"));
        mAtbRect.setPosTex(program->getAttrib("aTexCoord"));
        mAtbRect.draw();
        program->unuse();
    }

private:
    float mParam1{0.0};
    shared_ptr<STDSShaderProgram> mGlowLightProgram{nullptr};
};

#endif /* STDSGlowLightEffect_h */
